//
//  PurchaseHistoryTableViewCell.swift
//  LeTu
//
//  Created by gy on 2023/12/8.
//

import UIKit

class PurchaseHistoryTableViewCell: BaseTableViewCell {

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configUI()
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        
        DispatchQueue.main.async {
            _ = self.lineView.layer.sublayers?.map { $0.removeFromSuperlayer() }
            self.lineView.addDashedLine(color: .app_lineColor, dashedLineWidth: 6, lineHeight: CGFloat.app_lineHieght)
        }
    }
    static func getCellHeight() -> CGFloat {
        return 106
    }
    func setHistoryModel(_ historyModel: PurchaseHistoryModel) {
        vipTypeLabel.text = LanguageManager.shared.currentLanguage == .zh ? historyModel.title:historyModel.englishTitle
        payTimeLabel.text = "购买日期".localized + "：\(historyModel.createTime.components(separatedBy: " ").first ?? historyModel.createTime)"
        indateLabel.text = "会员有效期至".localized + "：\(historyModel.endTime.components(separatedBy: " ").first ?? historyModel.endTime)"
        priceLabel.text = "金额".localized + "：¥ \(historyModel.orderMoney.formattedString())"
    }
    
    // MARK: - configUI
    func configUI() {
        
        contentView.addSubview(backView)
        backView.addSubview(vipTypeLabel)
        backView.addSubview(payTimeLabel)
        backView.addSubview(indateLabel)
        backView.addSubview(priceLabel)
        contentView.addSubview(lineView)
        
        backView.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.right.equalTo(-20)
            make.centerY.equalToSuperview()
        }
        vipTypeLabel.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
        }
        payTimeLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(vipTypeLabel.snp.bottom)
        }
        indateLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(payTimeLabel.snp.bottom)
        }
        priceLabel.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(indateLabel.snp.bottom)
            make.bottom.equalToSuperview()
        }
        lineView.snp.makeConstraints { make in
            make.bottom.equalToSuperview()
            make.left.right.equalTo(backView)
            make.height.equalTo(CGFloat.app_lineHieght)
        }
        
    }
    private lazy var backView: UIView = {
        let backView = UIView()
        return backView
    }()
    private var vipTypeLabel: UILabel = {
        let vipTypeLabel = UILabel()
        vipTypeLabel.font = kSetPingFangMedium(16)
        return vipTypeLabel
    }()
    private var payTimeLabel: UILabel = {
        let payTimeLabel = UILabel()
        payTimeLabel.font = kSetPingFangRegular(12)
        payTimeLabel.textColor = .app_textGrayColor
        return payTimeLabel
    }()
    private var indateLabel: UILabel = {
        let indateLabel = UILabel()
        indateLabel.font = kSetPingFangRegular(12)
        indateLabel.textColor = .app_textGrayColor
        return indateLabel
    }()
    private var priceLabel: UILabel = {
        let priceLabel = UILabel()
        priceLabel.font = kSetPingFangRegular(12)
        priceLabel.textColor = .app_textGrayColor
        return priceLabel
    }()
    private lazy var lineView = UIView()
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
